<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			let state=false
			function turn(){
				let img=document.querySelector(".con>img") 
				let h1=document.querySelector(".con>img+h1")
				//1记录点击次数(基数开偶数关)
				//2读取现在页面的状态(获取灯的地址是on还是off)
				//3手动记录开关灯状态
				if(state){
					img.setAttribute("src","../src/off.png")  //改属性 图片
					h1.innerHTML="灯灭了" //改文本innerHtml innerText textContent
					h1.setAttribute("style","color:#000000")  //改样式
					state=false
				}
				else{
					img.setAttribute("src","../src/on.png")  //改图片
					h1.innerHTML="灯亮了"
					h1.setAttribute("style","color:#ff0000")
					state=true
				}
			}
		</script>
	</head>
	<body>
		<div class="con" style="text-align: center;" onclick="turn()">
			<img src="../src/off.png" width="150px" >
			<h1>点击开灯</h1>
		</div>
	</body>
</html>
